<?php
$action = $_POST['action'];
$username = $_POST['username'];
$ret['succ'] = 0;
if($username=="") 
{
	$ret['succ'] = 0;
	echo json_encode($ret);
	exit;
}
$filename = "./{$username}-data.txt";
if($action=="save")
{
	
	$username = $_POST['username'];
	//serialize
	
	$pdata = stripslashes($_POST['data']);
	print_r($pdata);
	$jdata = json_decode($pdata);

	if(count($jdata)>0)
	{
		$ret['succ'] = 1;
		file_put_contents($filename,serialize($jdata));
	}
	//$data = unserialize(file_get_contents());
	$ret['filename'] = $filename;
	echo json_encode($ret);
}
if($action=="load")
{
	$jdata = unserialize(stripslashes(file_get_contents($filename)));
	$ret['succ'] = 1;
	$ret['data'] = json_encode($jdata);
	echo json_encode($ret);
}